﻿using System;
using System.Collections.Generic;
using System.Text;

namespace AAA.DataTransfer
{
    public class NumericGroupAction : IGroupAction
    {
        private double _dInitValue = 0;

        public object InitValue
        {
            get { return _dInitValue; }
            set { _dInitValue = (double)value; }
        }


        private string _strFormat;

        public NumericGroupAction() 
            : this(null)
        {
        }

        public NumericGroupAction(string strFormat)
        {
            _strFormat = strFormat;
        }
        #region IGroupAction 成員

        public object Group(object oFirst, object oSecond)
        {
            if ((oFirst == null) || (oFirst is DBNull))
                oFirst = InitValue;
            if ((oSecond == null) || (oFirst is DBNull))
                oSecond = InitValue;

            double dResult = Convert.ToDouble(oFirst) + Convert.ToDouble(oSecond);

            if (_strFormat == null)
                return dResult;

            return dResult.ToString(_strFormat);
        }

        #endregion
    }
}
